jQuery.net={};

jQuery.net.clone= function (obj){
	var r={};
	Object.getOwnPropertyNames(obj)
	typeof(this[key]) == 'object'
	
}

jQuery.net.expand=function(option){	
	var opt=jQuery.extend({},this._default,option);
	for(var i in opt){
		if(jQuery.isFunction(opt[i])){
			this[i]=opt[i]();
		}else{
			this[i]=opt[i];
		}
	}
}
jQuery.net.expand.prototype={
	'_default':{},
	'_add':function(obj){
		jQuery.extend(this,obj);
		return this;
	},
	'_set':function(){
		for(var i in this){
			if(i[0]=='_') continue;
			var value=this[i];
			jQuery('[name='+i+'],#'+i).each(function(){
				this.value=value;
			});
		}
	},
	'_toString': function(){
		var html="";
		for(var i in this._default){
			if(i[0]=='_') continue;
			html+="&"+i+"="+this._default[i];
		}
		return html;
	}
}

jQuery.net.useInfo=function(option){
	var re=/[^\x00-\xff]/;
	var userId2=re.test(option.userId)?gw.convert(option.userId):option.userId;
	jQuery.extend(this,option);
	this.userId2=userId2;
	this.reqInfo={'time':0,'req':new XMLHttpRequest()};
}
jQuery.net.useInfo.prototype={
	'_send':function(tid){
		var tidInfo=jQuery.net.panel.tidInfos[tid];
		var l=tidInfo.mess.length,j=tidInfo.j;
		jQuery.extend(this,{'tid':tid,'mess':tidInfo.mess[tidInfo.j++%l],'num':1});
		var that=this;	
		req.addEventListener("load", function(){
				var req=that.reqInfo['req'],l=tidInfo.mess.length;
				if (this.readyState == 4) { 		
					if(req['time']!=0){
						clearTimeout(req['time']),req['time']=0;
					}
					if(tidInfo.ch){
						that['mess']=tidInfo.mess[tidInfo.j++%l];
					}
					that['num']++;
					if(tidInfo.num==0||that['num']<=tidInfo.num){
						tid==that['tid']&&tidInfo['send']=='send'&&setTimeout(_p,5500,i);	
					}
				}
			}, true);		
		this._post();
	},
	'_post':function (){
		var req=this.reqInfo['req'],tidInfo=jQuery.net.panel.tidInfos[this['tid']];
		req.open('POST', tidInfo.url, true); 
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.setRequestHeader('wgu',ckManage.toString(this['cookie']));
		req.send('subject='+this['expand']._toString()+'&message='+this['mess']);
		this.reqInfo['time']=setTimeout(_reload,config._reloadT,i);		
	}
	
}


jQuery.net.reqInfo=function(option){
	jQuery.extend(this,option);
}

jQuery.net.config={
	'sendURL':'http://bbs.2500sz.com/bbs/forum.php?mod=post&action=reply&fid={#fid}&tid={#tid}&extra=page%3D1&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1',
	'lockURLT':'http://bbs.2500sz.com/bbs/forum.php?mod=redirect&tid={#tid}&goto=lastpost',
	'lockT':10000,
	'lookT':3000,
	'lookfl':50,
	'sendfl':7
}



jQuery.net.panel= {
	'useInfos':[],
	'tidInfos':{}
};
jQuery.net.panel.__proto__={
	'_add':function(op){
		this.useInfos.push(new jQuery.net.useInfo(op)._init());
		return this;
	},
	'_panel':function (x){
		var html=[],t1='<option value="{#i}">{#name}</option>';
		var html2=[],t2='<span ><input type="checkbox" checked name="useInfo" value="{#i}">{#name}</span>';
		var useInfos=this.useInfos;
		useInfos.forEach(function (v,i){
			if(v.name==x){
				html.unshift(t1.format({'i':i,'name':v.name}));
			}else{
				html.push(t1.format({'i':i,'name':v.name}));
			}
			html2.push(t2.format({'i':i,'name':v.name}));
		});
		if(jQuery("#wgu_tool").length==0){
			jQuery('<div id="wgu_tool" style="bottom:0px;border-width: 1px;position: fixed;border-style: solid;border-radius: 11px 11px 0px 0px;padding:5px;background-color:White;">'
				+'<div><select id="wgu_sel" >'+html.join('')+'</select></div>'
				+'<div>'+html2.join('')+'</div>'
				+'<div>welcome to my tools! welcome to my tools! </div>'
				+'</div>').appendTo('body');
			jQuery('#wgu_sel').bind('change',function (){
				var i=this.value;
				gw.ckManage(location.hostname).remove().set(useInfos[i]['cookie']);
				if(!!useInfos[i].expand){
					useInfos[i].expand._set();
				}
			});
		}else{
			jQuery("#wgu_tool").html('<div><select id="wgu_sel" >'+html.join('')+'</select></div>'
				+'<div>'+html2.join('')+'</div>'
				+'<div>welcome to my tools! welcome to my tools! </div>');
		}
		return this;
	},
	'_send':function(message){
		var fid=window.fid,tid=window.tid,config=jQuery.net.config;
		var tidInfo=this.tidInfos[tid]={'fid':fid,'tid':tid,'mess':message,'fl':jQuery('#wgu_fl').val().split(','),'send':'send','isLock':false};
		var url=config.sendURL.format(tidInfo);
		gw.ob.add('request',url,'get','Cookie','wgu');
		gw.ob.add('request',url,'set','wgu',null);
		
		var num=jQuery('#wgu_num').val()||0;
		jQuery.extend(tidInfo,{'url':url,'num':num,'ch':jQuery('#wgu_ch')[0].checked,'j':0});
		
		if(num==0){
			this._lock(tid)();
		}
		document.getElementsByName('useInfo').forEach(function(v){
			if(v.checked){
				jQuery(v).parent()[0].style.color='olivedrab';
				this.useInfos[v.value]._send(tid);
			}
		})
	},
	'_post':function(tid){
		var reqInfos=this._reqInfos;
		for(var i in reqInfos){
			if(tid==reqInfos[i]['tid']&&this.tidInfos[tid]['send']=='send'){
				reqInfos[i]._post();
			}
		}
	},
	'_lock':function (tid,main,t){
		var main=main||true,config=jQuery.net.config;
		var t=t||config.lockT,url=config.lockUrlT.format(this.tidInfos[tid]);
		var req=new XMLHttpRequest(),that=this;
		req.addEventListener("load", function(){
				var tidInfo=that.tidInfos[tid];
				if (this.readyState == 4) { 
					var fl=parseInt(config.getfl(req.responseText));
					var flag=false;
					if(tidInfo.isLock==true){
						tidInfo['fl'].some(function(v){
							v=parseInt(v);
							if(fl<v-config.lookfl){
								flag=true;
								if(looking==true){
									looking=false;
									post(tid);
								}
								tidInfo['send']='send';
							}else if(v-config.lookfl<fl<v-config.sendfl&&v-config.lookfl>0){
								flag=true;
								tidInfo['send']='waite';
								t=config.lookT;
								if(looking==false){
									looking=true;
									for(var i=0;i<5;i++){
										that._lock(tid,false,t)();
									}
								}
							}else if(v-config.sendfl<=fl<=v&&v-config.lookfl>0){
								flag=true;
								if(looking==true){
									looking=false;
									that._post(tid);
								}
								t=config.lockT;
								tidInfo['send']='send';
							}
							return flag;
						})
					}else{
						tidInfo['fl'].some(function(v){
							v=parseInt(v);
							if(fl<=v+20){
								flag=true;
							}
							return flag;
						})
					}
					if(flag==false){
						tidInfo['send']='end';looking=false;
						var use=document.getElementsByName('useInfo');
						jQuery.net.panel.useInfos.forEach(function(v,i){
							if(v['tid']==tid){
								jQuery(use[i]).parent()[0].style.color='#000000';
							}
						});
					}else{
						if(main==false){
							looking==true&&setTimeout(_p,t);
						}else{
							setTimeout(_p,t);
						}
					}
				}
			}, true);
		function _p(){
			req.open('GET',url+'&wgu='+new Date().valueOf(), true); 
			req.send(null);
		}
		return _p;
	}
};